{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Chapter5a where

import Yesod
import Data.Text(Text)
import Text.Hamlet(shamlet)
import Text.Blaze.Html (toHtml,Html)

data App = App
mkYesod "App" [parseRoutes|
/ HomeR GET
|]
instance Yesod App

getHomeR = defaultLayout $ do
    setTitle "My Home Page"
    toWidget [lucius| hi{color:green:}|]
    addScriptRemote
        "http://img.cankaoxiaoxi.com/js/lib/jquery.js"
    toWidget
        [julius|
            $(function(){
                $("h1").click(function(){
                    alert("You clicked on the heading!")
                });
            });
        |]
    toWidgetHead
       metaHead
    toWidget
        $ toHtml $[hamlet|
            <h1>Here's one way of including content
            <a href=@{Apple}>
        |] renderFruits
            
    [whamlet|<h2>Here's another|]
    toWidgetBody
        [julius|
            alert("This is inclued in the body itself")
        |]
        
metaHead::Html
metaHead=toHtml [shamlet|
            <meta name=keywords content="some sample keywords">
            <meta name=search content=${show $name test}>
        |]
        where test= F{name="123"}

data Fruits = Apple|Banana deriving Show

data F = F{name::String}

renderFruits :: Fruits->[(Text,Text)] ->Text
renderFruits Apple _ = "Apple"
renderFruits Banana _ = "Banana"
        
main :: IO ()
main = warp 3000 App
